#include "init.h"
#include "AITeamState.h"

///////////////////////////////////////////////////////
////					DEFINITION CODE HERE
///////////////////////////////////////////////////////


///////////////////////////////////////////////////////
////					DON'T TOUCH MAIN
///////////////////////////////////////////////////////
int main(int argc, char* argv[]) {
	srand ( time(NULL) );

	Get_BOT_Name(argc,argv);
	FootBallMatch::Update = &AI_Update;
	FootBallMatch::Init = &AI_Init;
	FootBallMatch::Penalty = &AI_SetPenalty;
	FootBallMatch::EndGame = &AI_EndGame;
	AppClientHandlerPtr temp(new AppClientHandler());
	s_con_handler = temp;
	p_Fooball_Match = new FootBallMatch(LEFT,bot_table_x,bot_table_y,bot_name,bot_avatar);
	boost::thread thr_cGame(boost::bind(&FootBallMatch::Run,p_Fooball_Match,s_con_handler));
	Connection();
	thr_cGame.join();
	delete p_Fooball_Match;
    return 0;
}






///////////////////////////////////////////////////////
////					DECLARATION CODE HERE
///////////////////////////////////////////////////////
bool BallInOwnerPlace(FootBallMatch* _this)
{
	vector2d vBall2Goal = _this->GameBall()->Pos() - _this->Goal_Team();
	return vBall2Goal.Length()<(PITCH_WIDTH/2);
}

void AI_Init(FootBallMatch* team) 
{
	std::cout<<"\nINIT YOUR BOT HERE!!!"<<std::endl;
	AITeamState::GetInstance()->Init(team);	
}
void AI_SetPenalty(FootBallMatch* _this){
		std::cout<<"\nGAME PENALTY!\n";
		for(int i = 0; i<20;i++)
		{
			penalty_arr[i] = rand()%3;
		}
		_this->SetPenaltyArray(penalty_arr);
}
void AI_EndGame(FootBallMatch* _this)
{
	std::cout<<"\nGAME EXIT,  SCORE:"<<_this->Score().x<<" : "<<_this->Score().y<<std::endl;
}
void AI_Update(FootBallMatch* _this)
{
	//_this->Debug_Console_Output(true);
/***************************************************/
	AITeamState::GetInstance()->Update(_this);
}
